﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using Core;

namespace DAL
{
    public class KhachHangDAL
    {
        public static List<KhachHang> LayTatCa()
        {
            try
            {
                return CBO.FillCollection<KhachHang>(DataProvider.Instance.ExecuteReader("KhachHang_LayTatCa"));
            }
            catch
            {

                return new List<KhachHang>();
            }
        }
        public static bool Them(KhachHang tt)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQueryWithOutput("@IDKhachHang", "YeuCau_HoTro_KhachHang_Them", tt.IDKhachHang, tt.HoKH, tt.TenKH, tt.DiaChi, tt.SCMND, tt.SoDienThoai, tt.IDTinhTP);
                return Convert.ToInt32(rs) > 0;

            }
            catch
            {

                return false;
            }
        }
        public static bool Sua(KhachHang tt)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("KhachHang_Sua", tt.IDKhachHang, tt.HoKH, tt.TenKH, tt.DiaChi, tt.SCMND, tt.SoDienThoai, tt.IDTinhTP);
                return Convert.ToInt32(rs) > 0;

            }
            catch
            {

                return false;
            }
        }
        public static bool Xoa(string ID)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("KhachHang_Xoa", Convert.ToInt32(ID));
                return Convert.ToInt32(rs) > 0;

            }
            catch
            {

                return false;
            }
        }
        public static KhachHang LayID(string Id)
        {
            try
            {

                return CBO.FillObject<KhachHang>(DataProvider.Instance.ExecuteReader("KhachHang_LayID", Convert.ToInt32(Id)));
            }
            catch
            {

                return null;
            }
        }

    }
}
